// pages/supplier/index/index.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        result:{},
        manageList: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
    },
    // info
    supplierInfo() {
        let that = this
        wx.showLoading({
            title: "Loading..."
        });
        util.request(api.supplier.supplierInfo,{}, "GET")
            .then((res) => {
                console.log(res)
                that.setData({
                    result:res.result,
                    manageList:[
                        {
                            title: "商品管理",
                            imageUrl:"/static/images/gys-index-5.png",
                            url: "/pages/supplier/goodsCenter/goodsCenter?supplierId="+res.result.supplierId
                        },
                        {
                            title: "订单管理",
                            imageUrl:"/static/images/gys-index-3.png",
                            url: "/pages/supplier/orderManage/orderManage?supplierId="+res.result.supplierId
                        },
                        {
                            title: "财务中心",
                            imageUrl:"/static/images/gys-index-1.png",
                            url: "/pages/supplier/financeCenter/financeCenter?supplierId="+res.result.supplierId
                        },
                        {
                            title: "承保金",
                            imageUrl:"/static/images/gys-index-2.png",
                            url: "/pages/supplier/moneyManage/moneyManage?status="+res.result.supplierStatus.value+"&total="+res.result.depositAmount
                        },
                        {
                            title: "呼叫客服",
                            imageUrl:"/static/images/gys-index-4.png",
                            url: ""
                        }
        
                    ]
                })
                wx.hideLoading();
            })
            .catch((err) => {
                console.log(err)
                wx.hideLoading();
                wx.showToast({
                    title: err.message,
                    icon: "none",
                });
            });
    },
    goTo(e){
        let { url, title } = e.currentTarget.dataset;
        
        if(title=='呼叫客服'){
            wx.showActionSheet({
                itemList: ['客服1', '客服2', '客服3'],
                success (res) {
                    console.log(res.tapIndex)
                    if(res.tapIndex === 0){
                        wx.makePhoneCall({
                          phoneNumber: '13434399443',
                        })
                    }
                    if(res.tapIndex === 1){
                        wx.makePhoneCall({
                          phoneNumber: '13433499443',
                        })
                    }
                    if(res.tapIndex === 2){
                        wx.makePhoneCall({
                          phoneNumber: '13433493443',
                        })
                    }
                },
                fail (res) {
                    console.log(res.errMsg)
                }
            })
            return
        }
        if(this.data.result.supplierStatus.value == 2 && title!='承保金'){
            wx.showToast({
                icon:'error',
                title: '请先缴纳承保金',
            })
            return
        }
        wx.navigateTo({
            url: url,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.supplierInfo()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})